package cn.wolfcode.shop.cloud.service.impl;

import cn.wolfcode.shop.cloud.RedisService;
import cn.wolfcode.shop.cloud.domain.SecKillOrder;
import cn.wolfcode.shop.cloud.mapper.SeckillOrderMapper;
import cn.wolfcode.shop.cloud.service.ISecKillOrderService;
import cn.wolfcode.shop.cloud.util.SecKillKeyPrefix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SecKillOrderServiceImpl implements ISecKillOrderService {

    @Autowired
    private SeckillOrderMapper seckillOrderMapper;

    @Autowired
    private RedisService redisService;


    @Override
    public SecKillOrder queryByUserIdAndSeckillId(Long uid, Long seckillId) {
        return seckillOrderMapper.queryByUserIdAndSeckillId(uid, seckillId);
    }

    @Override
    public void createSeckillOrder(Long userId, Long seckillId, String orderNo) {
        seckillOrderMapper.createSecillOrder(userId, seckillId, orderNo);
        redisService.set(SecKillKeyPrefix.SECKILL_ORDER,userId+":"+seckillId,true);
    }
}
